from flask import Flask,url_for
from flask_restful import Api,Resource,reqparse,inputs,fields,marshal_with
app = Flask(__name__)

api = Api(app)

# class LoginView(Resource):
# #     def post(self,username=None):
# #         # from datetime import datetime
# #         # print(datetime.now()) 原生的 为  2019-05-16 12:23:12
# #         parser = reqparse.RequestParser()
# #         parser.add_argument('username',type=int,help="用户名必须为字符串",required=True)
# #         parser.add_argument('gender',type=str,choices=['male','female','secret'])
# #         parser.add_argument('telephone',type=inputs.regex(r'1[35789]\d{9}'))
# #         parser.add_argument('birthday',type=inputs.date,help='生日祝福') #2019-05-16 只需要年月日
# #         parser.add_argument('homepage',type=inputs.url,help='url类型不符合') #2019-05-16 只需要年月日
#          parser.parse_args()
# #
# #         return {"username":"91wangfan兄"}
# # api.add_resource(LoginView,'/login/<username>/','/signin/')
# #
# # # with app.test_request_context():
# # #     print(url_for('jiangjie'))
# # #url_for()

#输出
class Article(object):
    def __init__(self,username,age,school):
        self.username=username
        self.age=age
        self.school=school

article = Article(username="lingyuxiong",age=18,school='hafoo')
class ArticleView(Resource):
    resource_fields = {   #不管你方法中是否有这些字段  我都会给你返回  只不过是默认值或者空
        'username': fields.String, #以后开发的过程中 不管你要不要 我都会给你
        'age': fields.Integer,
        'school': fields.String,
        'height':fields.String
    }

    @marshal_with(resource_fields)
    def get(self):
        return article
    def post(self):
        pass

api.add_resource(ArticleView,'/article/',endpoint='article')

@app.route('/')
def hello_world():
    return 'Hello World!'


if __name__ == '__main__':
    app.run()
